package org.leumasjaffe.initiativeTracker.distributed.controller;


import org.eclipse.jdt.annotation.NonNullByDefault;
import org.leumasjaffe.initiativeTracker.entity.CharacterList;
import org.leumasjaffe.initiativeTracker.operator.CharacterDecoder;
import org.leumasjaffe.initiativeTracker.operator.InitiativeController;
import org.w3c.dom.NodeList;

import edu.wpi.heineman.xml.Message;
import edu.wpi.heineman.client.IMessageHandler;

@NonNullByDefault
public class CharacterHandler implements IMessageHandler {

	@SuppressWarnings("null")
	@Override
	public void process(Message response) {
		NodeList nl = response.contents.getFirstChild().getChildNodes();
		String id = response.contents.getFirstChild().getAttributes()
				.getNamedItem("game").getNodeValue();
		CharacterList list = InitiativeController.tracker(id).list;
		
		for (int i = 0; i < nl.getLength(); i++)
			list.insert(CharacterDecoder.decode(nl.item(i)/*.getAttributes()/**/, id));
	}
	
	@Override
	public IMessageHandler newCopy() {
		return new CharacterHandler();
	}
	
}
